#include "uvthread.h"
#include <unistd.h>
#include <cassert>

#define ADDITION 0
#define SUBTRACTION 1
#define DIVISION 2
#define MULTIPLICATION 3

size_t value = 2;

typedef struct {
    size_t value;
    int operation;
} ThreadData_t;

class SampleThread : public uv::thread::RecurrentThread {
public:
    void task(void *arg) {
        ThreadData_t *data = (ThreadData_t*) arg;
        switch (data->operation) {
            case ADDITION:
                value += data->value;
                break;
            case SUBTRACTION:
                value -= data->value;
                break;
            case DIVISION:
                value /= data->value;
                break;
            case MULTIPLICATION:
                value *= data->value;
                break;
        }
    }
};

int main() {
    ThreadData_t op[2];
    op[0].value = 5;
    op[0].operation = ADDITION;
    op[1].value = 2;
    op[1].operation = MULTIPLICATION;

    SampleThread t;
    // 2+5
    assert(t.tick((void *)&op[0]));
    // 7*2
    assert(t.tick((void *)&op[1]));
    while (!t.isReady()) {}
    assert(t.tickBlocking((void *)&op[0]));

    t.join();
    assert(value == 19);
    return 0;
}
